<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /**
       * 把字符剪刀,石头,布转换为数字0,1,2
       */
      function function5(a) {
        switch (a) {
          case "剪刀":
            return 0;
            break;
          case "石头":
            return 1;
            break;
          case "布":
            return 2;
            break;
        }
      }
      /**
       * 把数字0,1,2转换为字符剪刀,石头,布
       */
      function function6(a) {
        switch (a) {
          case 0:
            return "剪刀";
            break;
          case 1:
            return "石头";
            break;
          case 2:
            return "布";
            break;
        }
      }
      /**
       * 传入玩家猜出的手拳
       */
      function function4(d) {
        //模拟机器猜出的手拳
        var b = Math.floor(Math.random() * 3);
        console.log("电脑使出" + function6(b));
        //判断结果
        if (b == 0) {
          switch (d) {
            case 0:
              return "平手";
              break;
            case 2:
              return "你输了";
              break;
            case 1:
              return "你赢了";
              break;
          }
        } else if (b == 1) {
          switch (d) {
            case 2:
              return "你赢了";
              break;
            case 1:
              return "平手";
              break;
            case 0:
              return "你输了";
              break;
          }
        } else {
          switch (d) {
            case 1:
              return "你输了";
              break;
            case 0:
              return "你赢了";
              break;
            case 2:
              return "平手";
              break;
          }
        }
      }

      function function2(a) {
        var b = parseInt(a);
        if (b == 0) {
          return 0;
        }
        if (!Boolean(b) || b < 0) {
          return -1;
        }
        return b * 0.23;
      }
      function function1(a) {
        var b = a - function2(a);
        if (b < 5000) {
          return 0;
        } else if (5000 < b && b <= 8000) {
          return b * 0.03;
        } else if (8000 < b && b <= 17000) {
          return b * 0.1;
        } else if (b > 17000 && b <= 30000) {
          return b * 0.2;
        } else if (b > 30000 && b <= 40000) {
          return b * 0.25;
        } else if (b > 40000 && b <= 60000) {
          return b * 0.3;
        } else if (b > 60000 && b <= 85000) {
          return b * 0.35;
        } else if (b > 85000) {
          return b * 0.45;
        }
      }
      var a = prompt("请输入你的税前工资");
      if (function2(a) != "-1") {
        document.write("个人所得税为：" + function1(a) + "元");
        document.write("<br>");
        document.write("缴纳社保：" + function2(a) + "元");
        document.write("<br>");
        var b = a - function1(a) - function2(a);
        document.write("最终工资：" + b + "元");
      } else {
        document.write("输入正确的数值才能计算工资");
      }

      //该代码没有健壮性
      var b = window.confirm("来一次猜拳吗？");
      while (b) {
        var c = window.prompt("请输入剪刀，石头，布");
        var d = function5(c); //将剪刀，石头，布 换算成0,1,2
        console.log("你使出" + function6(d)); //将0,1,2 换算成剪刀，石头，布
        //传入玩家猜出的手拳
        window.alert(function4(d));
        b = window.confirm("要再来一次吗？");
      }
    </script>
  </body>
</html>
